package com.by.charpter03;

import android.app.Application;
import android.media.MediaPlayer;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MApp extends Application {

    public static MApp APP = null ;

    private ExecutorService executorService = Executors.newFixedThreadPool(2);
    @Override
    public void onCreate() {
        APP = this;
        super.onCreate();
    }

    public ExecutorService getExecutor(){
        return executorService;
    }

    private MediaPlayer player ;

    public MediaPlayer getMedia(){
        if(player==null) {
            player = MediaPlayer.create(this, R.raw.music);
        }
        return player;
    }

    public void releaseMediaPlayer(){
        if (MApp.APP.getMedia() != null) {
            if (MApp.APP.getMedia().isPlaying()) {
                MApp.APP.getMedia().stop();
                MApp.APP.getMedia().release();
                player = null;
            }
        }
    }

}
